Skip to content

Conversation

@jrtc27
Copy link
Member

@jrtc27 jrtc27 commented May 30, 2025

  • [ELF] Consistently use gotEntrySize for GOT entries
  • [ELF][RISCV] Use .got rather than .captable for CHERI-RISC-V
  • [ELF][NFC] Drop unwarranted XXX comments
  • [ELF] Make .captable explicitly MIPS-specific
  • [ELF][RISCV] Don't set sizeRel
  • [ELF][RISCV] Don't set cheriCapCallRel
  • [RISCV] Drop CHERI-RISC-V-specific assembly modifiers and relocations
  • [BinaryFormat][RISCV] Mark no-longer used CHERI relocations deprecated
  • [BinaryFormat][RISCV] Ditch R_RISCV_CHERI_CAPABILITY_CALL in comment
  • [BinaryFormat][RISCV] Delete R_RISCV_CHERI_SIZE
  • [ELF][CHERI] Support creating new capability relocations against sections
  • [ELF][RISCV] Stop using CSub for capability subtraction
  • [ELF][RISCV] Support .got.plt with lazy binding for CHERI-RISC-V

d624134 ("[lld][X86] Restore gotEntrySize.") (re-)introduced
gotEntrySize and used it for various GOT calculations, but was not
exhaustive (nor consistent; Symbol::getGotOffset was modified but not
GotSection::finalizeContents, so we undercompute the size, on top of
computing the wrong offsets for TLS), and since then even more uses have
been added that use wordsize instead of gotEntrySize (presumably due to
looking at the existing incorrect ones).

This doesn't really matter upstream, as the only architecture where the
two differ is X32, and from looking at the code it's not properly
supported (e.g. TLS relaxation assumes LP64 sequences), but downstream
in CHERI LLVM it does matter, as CHERI's pointers are more than just an
integer address (a machine word).

Note this ignores the special MipsGotSection; on MIPS, wordsize and
gotEntrySize are the same, CHERI-MIPS is no longer something we support
downstream and even when we did we didn't reuse that implementation.
@jrtc27 jrtc27 force-pushed the cheri-got branch 2 times, most recently from cd663e2 to 9cafdd4 Compare May 30, 2025 23:15
@jrtc27
Copy link
Member Author

jrtc27 commented May 30, 2025

I'll deal with the clang-format bits I missed later (and won't be accepting the lld ones, that's upstream's formatting...)

@jrtc27
Copy link
Member Author

jrtc27 commented May 31, 2025

This can do a clean build of CheriBSD that passes all cheribsdtest tests.

@jrtc27
Copy link
Member Author

jrtc27 commented May 31, 2025

NB: The first commit is up for review upstream at llvm/llvm-project#142064

@jrtc27
Copy link
Member Author

jrtc27 commented May 31, 2025

Now with opt-in .got.plt support (requires CTSRD-CHERI/cheribsd#2417 if enabled).

jrtc27 added 12 commits June 1, 2025 03:22
RELRO sections are SHF_WRITE, so there's nothing wrong with the code
here. This is how it's meant to work, and how things like GotSection are
constructed.
CHERI-RISC-V no longer uses it, and Morello never has downstream.
This exists to support __cap_relocs for preemptible symbols, but that
was always a bit broken and was replaced long ago even on CHERI-MIPS
with proper ELF relocations (though the option not to still exists).
CHERI-RISC-V never used this, and CheriBSD does not support it.
This was never on CHERI-RISC-V even when we used .captable, as we passed
R_CHERI_CAPABILITY_TABLE_INDEX to ensure the relocation was in .rela.dyn
and thus would also use cheriCapRel rather than cheriCapCallRel. Now the
normal .got is used instead there isn't even a path that could use this.
LLD is now using a normal GOT so all the captable-related names are a
misnomer, instead they should be the same as the normal GOT ones. We can
also drop various other gratuitously-different relocations and modifiers
whilst here. The idea was to make it possible to support mixing integer
and capability mode instructions when it comes to instructions that need
relocations, but that comes down to the same problem that R_RISCV_RELAX
faces when it comes to .option arch, so we shouldn't be doing something
special here that leads to a bunch of unnecessary divergence.

As far as I know we don't have any assembly in our software stack that
uses these modifiers, it all uses the pseudos that hide this detail.
We can just reuse R_RISCV_JUMP_SLOT when needed.
This has never actually been used (it only appeared to be used in LLD,
but never was in practice), nor is it supported by any run-time linker.
…ions

This will be needed to initialise .got.plt entries to refer to .plt[0].
The infrastructure is already mostly there, we just need to expose it
via the addCapabilityRelocation interface and remove some assumptions.
This code is currently dead since we emit an all-zeroes PLT header on
CHERI-RISC-V, but will soon be used.

Fixes: 05652b9 ("[CHERI-RISC-V] Remove CSub")
This is currently behind an opt-in -z cheri-riscv-jump-slot flag as it
requires support in CheriBSD, but in future will become the default and
only supported mode.
@jrtc27 jrtc27 merged commit a913ff1 into dev Jun 3, 2025
5 of 6 checks passed
@jrtc27 jrtc27 deleted the cheri-got branch June 3, 2025 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants